 <? include("/inc/header.html") {} ?>
 
 <div class="col-lg-5">
   	<div class="panel" overflow: auto;">
          <div class="panel-body pan "style="width:auto; overflow: auto;" >
			<div class="form-body pal" style="float:left;width:100%; overflow: auto;"  >
			<div>
					<label for="inputUsername" class="col-md-3 control-label">
				 		<div align="right">范围
							<span class='require' id="paixu">*</span></div>
                   	 </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="scope" class="form-control">
									<option value="0">全库有效</option>
									<option value="1">单库有效</option>
								</select>
							</div>
						</div>
					</div>
					<div id="showrequire" style="display: none;">
					<label for="inputUsername" class="col-md-3 control-label">所属类
						<span class='require' id="paixu">*</span> </label>
					<div class="col-md-9">
						<div class="input-group input-group-sm mbs" >
							 <input id="parentclassname" type="text" placeholder="请选择类"  class="form-control" disabled="true"  />
							  <span class="input-group-btn"><button id="buttonid" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>		
						</div>
					</div>
				</div>
<!-- 				<div style="display: none;"> -->
<!-- 					<label class="col-md-3 control-label">排序方式 -->
<!-- 						<span class='require' id="paixumethod">*</span> </label> -->
<!-- 						<div class="col-md-9"> -->
<!-- 						<div class="input-icon" > -->
<!-- 							<select id="sortMethod" type="text" class="form-control" onchange="changeSortMethod(this);"> -->
<!-- 								<option value="0">简单排序</option> -->
<!-- 								<option value="1" selected="selected">复杂排序</option> -->
<!-- 							</select> -->
<!-- 						</div> -->
<!-- 					</div> -->
<!-- 				</div> -->
				
				<div id="simpleSort" style="display: none;">
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">中文名称
							<span class='require' id="zhongwenName">*</span></div>
	                    </label>
						<div class="col-md-7">
							<div class="input-icon" >
								<select id="simpleNameZh" type="text" class="form-control" onchange="setEnName(this);">
									<option value="-1">请选择</option>
								</select>
							</div>
						</div>
					</div>
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">英文名称
							<span class='require' id="yingwenName">*</span></div>
	                    </label>
						<div class="col-md-7">
							<div class="input-icon" >
								<select id="simpleNameEn" type="text" class="form-control" disabled="disabled">
									<option value="-1">请选择</option>
								</select>
							</div>
						</div>
					</div>
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">策略
							<span class='require' id="yingwenName">*</span></div>
	                    </label>
						<div class="col-md-7">
							<div class="input-icon" >
								<select id="simpleSortExpression" type="text" class="form-control">
									<option value="asc">升序</option>
									<option value="desc">降序</option>
								</select>
							</div>
						</div>
					</div>
				</div>
				<div id="complexSort" style="display: block;">
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">中文名称
							<span class='require' id="zhongwenName">*</span></div>
	                    </label>
						<div class="col-md-7">
							<div class="input-icon" >
								<input id="complexNameZh" type="text" class="form-control"></input>
							</div>
						</div>
					</div>
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
						  <div align="right">英文名称
							<span class='require' id="yingwenName">*</span></div>
	                    </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="complexNameEn" type="text" class="form-control" /> 
							</div>
						</div>
					</div>
					<div>
					<label for="inputUsername" class="col-md-3 control-label">
				 		<div align="right">策略
							<span class='require' id="paixu">*</span></div>
                   	 </label>
						<div class="col-md-9">
							<div class="input-icon">
								<textarea id="complexSortExpression" rows="8" class="form-control" ></textarea>
							</div>
						</div>
					</div>
				</div>
				<div>
					<label for="inputUsername" class="col-md-3 control-label">
					  <div align="right">前台列表页面展示顺序
						<span class='require' id="yingwenName">*</span></div>
                    </label>
					<div class="col-md-7">
						<div class="input-icon">
							<input id="sort" type="text"  class="form-control"  />
						</div>
					</div>
				</div>
			</div>
			<input id="parentClassid" type="hidden" value="" class="form-control" />
		</form>
	</div>
  </div>
</div>
<script type="text/javascript">
	var id = window.parent.getsortId();
	var curr = window.parent.getcurr();
	var className = window.parent.getClassName();
	if(id !=0){
		$.ajax({
			type : "post",
			url : "querySortUplaod.do",
			dataType : "json",
			data:{
				"id":id
			},
			beforeSend : function(XMLHttpRequest) {},
			success: function(data) {
           		 //alert(JSON.stringify(data));
           		 $("#complexNameZh").val(data.nameZh);
           		 $("#complexNameEn").val(data.nameEn);
           		 $("#sort").val(data.sort);
           		 $("#complexSortExpression").val(data.sortExpression);
           		 if(data.scope == '1'){
           		 	$("#scope").val(data.scope);
           		 	$("#showrequire").show();
           		 	$("#parentClassid").val(data.classesId);
           		 	$("#parentclassname").val(className);
//            		 	xianshidata();
           		 }
    		}
		});
	}
	$(document).ready(function () { 
		  $("#scope").bind("change",function(){ 
// 		  	$("#simpleNameZh").html("");
// 			$("#simpleNameEn").html("");
			/* $("#complexNameZh").val("");
// 			$("#complexNameEn").val("");*/
		    if($(this).val() == 1){
		   		$("#showrequire").show();
		    }else{
		    	$("#showrequire").hide();
		    	$("#parentClassid").val("");
		    	$("#parentclassname").val("");
// 		    	if($("#sortMethod").val() == '0'){
// 			    	listCustomFields(); 
// 		    	}
		    }
		  }); 
	});
	function listCustomFields(){
		$.ajax({
					type : "post",
					url : "./listAllCommonDataCnAndEnName.do",
					dataType : "json",
					async : false,
					success : function(data) {
						var fieldCnName = '';
						var fieldEnName = '';
						for ( var i = 0; i < data.length; i++) {
							fieldCnName += '<option value="'+data[i].nameZh+'" name="'+data[i].nameEn+'">'+data[i].nameZh+'('+data[i].nameEn+')</option>';
							fieldEnName += '<option value="'+data[i].nameEn+'">'+data[i].nameEn+'</option>';
						}
						$("#simpleNameZh").html(fieldCnName);
						$("#simpleNameEn").html(fieldEnName);
					},
					error : function(data) {
						alert("请求失败");
					}
				});
		
	}
	//查询类
    function saveclassZTree() {
		parent.layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择父节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["search-weight-classes-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
// 			   if($("#sortMethod").val() == '0'){
// 				   xianshidata();
// 			   }
			},
			cancel : function(index) {
			}
		});
	};
	function save(){ 
		var data = {};
		//if($("#sortMethod").val() == '1'){
			data["nameZh"] = $("#complexNameZh").val();
			data["nameEn"] = $("#complexNameEn").val();
			data["sortExpression"] = $("#complexSortExpression").val();
// 		}else{
// 			data["nameZh"] = $("#simpleNameZh").val();
// 			data["nameEn"] = $("#simpleNameEn").val();
// 			data["sortExpression"] = $("#simpleSortExpression").val();
// 		}
		data["scope"] = $("#scope").val();
		if($("#scope").val() == '1'){
			data["classesId"] = $("#parentClassid").val();
		}
		data["sort"] = $("#sort").val();
// 		data["isComplexSort"] = $("#sortMethod").val();
		data["id"] = id;
		$.ajax({
			type : "post",
			url : "sortAddUpload.do",
			dataType : "json",
			data:data,
			beforeSend : function(XMLHttpRequest) {},
			success: function(data) {
           		 var index = parent.layer.getFrameIndex(window.name); 
           		 window.parent.sortList(curr);
           		if(data == 'yes'){
	           		if(id ==0){
	           			parent.layer.msg('添加成功！');
	           		}else{
	           			parent.layer.msg('修改成功！');
	           		}
           		}else if(data == 'exist'){
           			parent.layer.msg('请勿重复添加排序策略');
           		}else{
           			if(id ==0){
	           			parent.layer.msg('添加失败！');
	           		}else{
	           			parent.layer.msg('修改失败！');
	           		}
           		}
            	 parent.layer.close(index); 
    		}
		});
    } 
    var classids;
    function getclassids(){
		return classids
	}
	
	function changeSortMethod(obj){
		if(obj.value == '1'){
			$("#complexSort").show();
			$("#simpleSort").hide();
		}else{
			$("#complexSort").hide();
			$("#simpleSort").show();
			if($("#parentClassid").val() != ''){
				xianshidata();
			}else{
				listCustomFields();
			}
		}
	}
	function xianshidata() {
		$.ajax({
					type : "post",
					url : "./KnowledgeDataPropertyList.do",
					data : {
						"lid" : $("#parentClassid").val()
					},
					dataType : "json",
					async : false,
					success : function(data) {
						var fieldCnName = '';
						var fieldEnName = '';
						for ( var i = 0; i < data.length; i++) {
							fieldCnName += '<option value="'+data[i].name+'" name="'+data[i].nameen+'">'+data[i].name+'('+data[i].nameen+')</option>';
							fieldEnName += '<option value="'+data[i].nameen+'">'+data[i].nameen+'</option>';
						}
						$("#simpleNameZh").html(fieldCnName);
						$("#simpleNameEn").html(fieldEnName);
					},
					error : function(data) {
						alert("请求失败");
					}
				});

	}
	function setEnName(obj){
		$("#simpleNameEn").val($("option[value='"+obj.value+"']").attr("name"));
	}
    //选择父类
// 	function saveclassZTree() {
	
// 	classids=$("#nameZh").val();
// 		layer.open({
// 			type : 2,
// 			area : [ '360px', '400px' ],
// 			fix : false, //不固定
// 			scrollbar : false,
// 			shadeClose : true,
// 			move : false,
// 			title:"属性选择",
// 			skin : 'layui-layer-rim', //加上边框
// 			btn : [ '保存 ', '关闭' ],
// 			content : ["search_editSave_department_zTree.html", 'no'],
// 			yes : function(index,layer) {		
// 			  var iframeWin = parent.window[window.name].window[layer.find('iframe')[0]['name']];
// 			  			  iframeWin.save();
// 			},
// 			cancel : function(index) {
// 			}
// 		});
// 	}
</script>
